package com.tyjt.vehfinder.listener;

import com.tyjt.common.mqtt.annotation.MqttListener;
import com.tyjt.vehfinder.core.actor.BsmMsg;
import com.tyjt.vehfinder.core.actor.VehMgr;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.stereotype.Component;

@Component
public class BsmListener {
    //  idse/bsm/{alg_id}/{vehid}
    @MqttListener("$share/idse/bsm/+/+")
    public void perceptionData(String topic, MqttMessage message) {
        try {
            System.out.println("到达时间" + System.currentTimeMillis());
            String[] split = topic.split("/");
            String vehId = split[split.length - 1];
            String companyId = split[split.length -2];
            BsmMsg bsmMsg = new BsmMsg(companyId,vehId,message.getPayload());
            VehMgr.getInstance().sendMsg2Veh(vehId, bsmMsg);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }


    }
}
